package cn.dnui_lf_705.dnui_16110100705.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dnui_lf_705.dnui_16110100705.R;
import cn.dnui_lf_705.dnui_16110100705.bean.CommentBean;
import cn.dnui_lf_705.dnui_16110100705.controller.CommentInfoActivity;


public class CommentInfoAdapter extends RecyclerView.Adapter<CommentInfoAdapter.ViewHolder> implements View.OnClickListener {
    private List<CommentBean> mDatalist;
    private Context mContext;
    private LayoutInflater mLayoutInflater;


    public CommentInfoAdapter(CommentInfoActivity pingLunActivity, List<CommentBean> commentBeans) {
            this.mDatalist = commentBeans;
            this.mContext = pingLunActivity;
            mLayoutInflater = LayoutInflater.from(mContext);
            notifyDataSetChanged();
    }


    @NonNull
    @Override
    public CommentInfoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v =mLayoutInflater.from(viewGroup.getContext()).inflate(R.layout.comments_item,viewGroup,false);
        v.setOnClickListener(this);
        return new CommentInfoAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull CommentInfoAdapter.ViewHolder viewHolder1, int i) {
        final CommentBean entity = mDatalist.get(i);
        if (entity==null)
            return;
        else
        {
            final CommentInfoAdapter.ViewHolder viewHolder = viewHolder1;
            viewHolder.content.setText(entity.getContent());
            viewHolder.comment_username.setText(entity.getUsername());
            viewHolder.comment_time.setText(entity.getComment_time());
        }

    }

    @Override
    public int getItemCount() {
        return mDatalist.size();
    }

    @Override
    public void onClick(View v) {

    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView content,comment_username,comment_time;
        public ViewHolder(View view) {
            super(view);
            content=view.findViewById(R.id.comment_text);
            comment_username=view.findViewById(R.id.comment_username);
            comment_time=view.findViewById(R.id.comment_time);
        }
    }
}
